home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 53 / IOPROG_53.ISO / soft / c++ / xceedftp.exe / Samples / Visual Basic / FTPClient / frmMain.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2000-10-05  |  74.0 KB  |  1,619 lines

  1. VERSION 5.00
  2. Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.2#0"; "COMCTL32.OCX"
  3. Object = "{FF8DA174-3574-11D4-8068-0060082AE372}#1.0#0"; "XCEEDFTP.DLL"
  4. Begin VB.Form frmMain 
  5.    BackColor       =   &H8000000B&
  6.    Caption         =   "FTP Client sample application"
  7.    ClientHeight    =   7245
  8.    ClientLeft      =   165
  9.    ClientTop       =   450
  10.    ClientWidth     =   12525
  11.    ClipControls    =   0   'False
  12.    Icon            =   "frmMain.frx":0000
  13.    LinkTopic       =   "Form1"
  14.    MousePointer    =   1  'Arrow
  15.    ScaleHeight     =   483
  16.    ScaleMode       =   3  'Pixel
  17.    ScaleWidth      =   835
  18.    StartUpPosition =   2  'CenterScreen
  19.    Begin ComctlLib.ProgressBar prgStatus 
  20.       Height          =   195
  21.       Left            =   6600
  22.       TabIndex        =   24
  23.       Top             =   7035
  24.       Width           =   5640
  25.       _ExtentX        =   9948
  26.       _ExtentY        =   344
  27.       _Version        =   327682
  28.       Appearance      =   0
  29.    End
  30.    Begin ComctlLib.StatusBar stbProgress 
  31.       Align           =   2  'Align Bottom
  32.       Height          =   255
  33.       Left            =   0
  34.       TabIndex        =   25
  35.       Top             =   6990
  36.       Width           =   12525
  37.       _ExtentX        =   22093
  38.       _ExtentY        =   450
  39.       SimpleText      =   ""
  40.       _Version        =   327682
  41.       BeginProperty Panels {0713E89E-850A-101B-AFC0-4210102A8DA7} 
  42.          NumPanels       =   4
  43.          BeginProperty Panel1 {0713E89F-850A-101B-AFC0-4210102A8DA7} 
  44.             Object.Width           =   7056
  45.             MinWidth        =   7056
  46.             Key             =   ""
  47.             Object.Tag             =   ""
  48.          EndProperty
  49.          BeginProperty Panel2 {0713E89F-850A-101B-AFC0-4210102A8DA7} 
  50.             Object.Width           =   1764
  51.             MinWidth        =   1764
  52.             Key             =   ""
  53.             Object.Tag             =   ""
  54.          EndProperty
  55.          BeginProperty Panel3 {0713E89F-850A-101B-AFC0-4210102A8DA7} 
  56.             Object.Width           =   2646
  57.             MinWidth        =   2646
  58.             Key             =   ""
  59.             Object.Tag             =   ""
  60.          EndProperty
  61.          BeginProperty Panel4 {0713E89F-850A-101B-AFC0-4210102A8DA7} 
  62.             AutoSize        =   1
  63.             Object.Width           =   10019
  64.             MinWidth        =   176
  65.             Key             =   ""
  66.             Object.Tag             =   ""
  67.          EndProperty
  68.       EndProperty
  69.    End
  70.    Begin VB.CommandButton cmdAbort 
  71.       Caption         =   "&Abort"
  72.       Height          =   375
  73.       Left            =   5790
  74.       TabIndex        =   3
  75.       ToolTipText     =   "Abort"
  76.       Top             =   1185
  77.       Width           =   975
  78.    End
  79.    Begin VB.CommandButton cmdRenameRemoteFile 
  80.       Caption         =   "Rename File"
  81.       Height          =   255
  82.       Left            =   8340
  83.       TabIndex        =   13
  84.       Top             =   5400
  85.       Width           =   1320
  86.    End
  87.    Begin VB.OptionButton optBinary 
  88.       Caption         =   "Binary"
  89.       Height          =   255
  90.       Left            =   5880
  91.       TabIndex        =   23
  92.       Top             =   4440
  93.       Width           =   735
  94.    End
  95.    Begin VB.OptionButton optAscii 
  96.       Caption         =   "ASCII"
  97.       Height          =   255
  98.       Left            =   5880
  99.       TabIndex        =   22
  100.       Top             =   4680
  101.       Width           =   735
  102.    End
  103.    Begin VB.CommandButton cmdDeleteRemoteFile 
  104.       Caption         =   "Delete File"
  105.       Height          =   255
  106.       Left            =   7020
  107.       TabIndex        =   12
  108.       Top             =   5400
  109.       Width           =   1320
  110.    End
  111.    Begin VB.CommandButton cmdCreateRemoteFolder 
  112.       Caption         =   "Create Folder"
  113.       Height          =   255
  114.       Left            =   9660
  115.       TabIndex        =   14
  116.       Top             =   5400
  117.       Width           =   1320
  118.    End
  119.    Begin VB.CommandButton cmdDeleteRemoteFolder 
  120.       Caption         =   "Delete Folder"
  121.       Height          =   255
  122.       Left            =   10980
  123.       TabIndex        =   15
  124.       Top             =   5400
  125.       Width           =   1320
  126.    End
  127.    Begin VB.CommandButton cmdDeleteLocalFile 
  128.       Caption         =   "Delete File(s)"
  129.       Height          =   255
  130.       Left            =   285
  131.       TabIndex        =   6
  132.       Top             =   5400
  133.       Width           =   1320
  134.    End
  135.    Begin VB.CommandButton cmdRenameLocalFile 
  136.       Caption         =   "Rename File"
  137.       Height          =   255
  138.       Left            =   1605
  139.       TabIndex        =   7
  140.       Top             =   5400
  141.       Width           =   1320
  142.    End
  143.    Begin VB.CommandButton cmdCreateLocalFolder 
  144.       Caption         =   "Create Folder"
  145.       Height          =   255
  146.       Left            =   2925
  147.       TabIndex        =   8
  148.       Top             =   5400
  149.       Width           =   1320
  150.    End
  151.    Begin VB.CommandButton cmdRemoveLocalFolder 
  152.       Caption         =   "Delete Folder"
  153.       Height          =   255
  154.       Left            =   4230
  155.       TabIndex        =   9
  156.       Top             =   5400
  157.       Width           =   1320
  158.    End
  159.    Begin VB.CommandButton cmdDisconnect 
  160.       Caption         =   "&Disconnect"
  161.       Height          =   375
  162.       Left            =   5790
  163.       TabIndex        =   2
  164.       ToolTipText     =   "Disconnect"
  165.       Top             =   720
  166.       Width           =   975
  167.    End
  168.    Begin VB.CommandButton cmdConnect 
  169.       Caption         =   "&Connect"
  170.       Height          =   375
  171.       Left            =   5790
  172.       TabIndex        =   1
  173.       ToolTipText     =   "Connect"
  174.       Top             =   240
  175.       Width           =   975
  176.    End
  177.    Begin VB.CommandButton cmdReceive 
  178.       Height          =   375
  179.       Left            =   5790
  180.       Picture         =   "frmMain.frx":030A
  181.       Style           =   1  'Graphical
  182.       TabIndex        =   5
  183.       Top             =   3360
  184.       Width           =   975
  185.    End
  186.    Begin VB.Frame fraRemote 
  187.       Caption         =   "Remote Server"
  188.       Height          =   5655
  189.       Left            =   6840
  190.       TabIndex        =   20
  191.       Top             =   120
  192.       Width           =   5600
  193.       Begin VB.ComboBox cboRemotePath 
  194.          Height          =   315
  195.          Left            =   120
  196.          Sorted          =   -1  'True
  197.          TabIndex        =   16
  198.          Tag             =   "0"
  199.          Top             =   240
  200.          Width           =   4815
  201.       End
  202.       Begin VB.CommandButton cmdUpFtp 
  203.          Height          =   315
  204.          Left            =   4975
  205.          Picture         =   "frmMain.frx":074C
  206.          Style           =   1  'Graphical
  207.          TabIndex        =   17
  208.          Top             =   240
  209.          Width           =   495
  210.       End
  211.       Begin ComctlLib.ListView lstRemoteFileList 
  212.          Height          =   4575
  213.          Left            =   120
  214.          TabIndex        =   21
  215.          Top             =   600
  216.          Width           =   5385
  217.          _ExtentX        =   9499
  218.          _ExtentY        =   8070
  219.          SortKey         =   3
  220.          View            =   3
  221.          LabelEdit       =   1
  222.          Sorted          =   -1  'True
  223.          MultiSelect     =   -1  'True
  224.          LabelWrap       =   -1  'True
  225.          HideSelection   =   0   'False
  226.          OLEDragMode     =   1
  227.          OLEDropMode     =   1
  228.          _Version        =   327682
  229.          Icons           =   "lstImageList"
  230.          SmallIcons      =   "lstImageList"
  231.          ForeColor       =   -2147483640
  232.          BackColor       =   -2147483643
  233.          BorderStyle     =   1
  234.          Appearance      =   1
  235.          OLEDragMode     =   1
  236.          OLEDropMode     =   1
  237.          NumItems        =   4
  238.          BeginProperty ColumnHeader(1) {0713E8C7-850A-101B-AFC0-4210102A8DA7} 
  239.             Key             =   ""
  240.             Object.Tag             =   ""
  241.             Text            =   "Name"
  242.             Object.Width           =   3351
  243.          EndProperty
  244.          BeginProperty ColumnHeader(2) {0713E8C7-850A-101B-AFC0-4210102A8DA7} 
  245.             SubItemIndex    =   1
  246.             Key             =   ""
  247.             Object.Tag             =   ""
  248.             Text            =   "Size (bytes)"
  249.             Object.Width           =   1940
  250.          EndProperty
  251.          BeginProperty ColumnHeader(3) {0713E8C7-850A-101B-AFC0-4210102A8DA7} 
  252.             SubItemIndex    =   2
  253.             Key             =   ""
  254.             Object.Tag             =   ""
  255.             Text            =   "Date"
  256.             Object.Width           =   3263
  257.          EndProperty
  258.          BeginProperty ColumnHeader(4) {0713E8C7-850A-101B-AFC0-4210102A8DA7} 
  259.             SubItemIndex    =   3
  260.             Key             =   ""
  261.             Object.Tag             =   ""
  262.             Text            =   ""
  263.             Object.Width           =   0
  264.          EndProperty
  265.       End
  266.    End
  267.    Begin VB.Frame fraLocal 
  268.       Caption         =   "Local System"
  269.       Height          =   5655
  270.       Left            =   120
  271.       TabIndex        =   18
  272.       Top             =   120
  273.       Width           =   5600
  274.       Begin VB.ComboBox cboLocalPath 
  275.          Height          =   315
  276.          ItemData        =   "frmMain.frx":0A8E
  277.          Left            =   120
  278.          List            =   "frmMain.frx":0A90
  279.          Sorted          =   -1  'True
  280.          TabIndex        =   10
  281.          Top             =   240
  282.          Width           =   4815
  283.       End
  284.       Begin VB.CommandButton cmdUpLocal 
  285.          Height          =   315
  286.          Left            =   4980
  287.          Picture         =   "frmMain.frx":0A92
  288.          Style           =   1  'Graphical
  289.          TabIndex        =   11
  290.          Top             =   240
  291.          Width           =   495
  292.       End
  293.       Begin ComctlLib.ListView lstLocalFileList 
  294.          Height          =   4575
  295.          Left            =   120
  296.          TabIndex        =   19
  297.          Top             =   600
  298.          Width           =   5385
  299.          _ExtentX        =   9499
  300.          _ExtentY        =   8070
  301.          SortKey         =   3
  302.          View            =   3
  303.          LabelEdit       =   1
  304.          Sorted          =   -1  'True
  305.          MultiSelect     =   -1  'True
  306.          LabelWrap       =   -1  'True
  307.          HideSelection   =   0   'False
  308.          OLEDragMode     =   1
  309.          OLEDropMode     =   1
  310.          _Version        =   327682
  311.          Icons           =   "lstImageList"
  312.          SmallIcons      =   "lstImageList"
  313.          ForeColor       =   -2147483640
  314.          BackColor       =   -2147483643
  315.          BorderStyle     =   1
  316.          Appearance      =   1
  317.          OLEDragMode     =   1
  318.          OLEDropMode     =   1
  319.          NumItems        =   4
  320.          BeginProperty ColumnHeader(1) {0713E8C7-850A-101B-AFC0-4210102A8DA7} 
  321.             Key             =   ""
  322.             Object.Tag             =   ""
  323.             Text            =   "Name"
  324.             Object.Width           =   3351
  325.          EndProperty
  326.          BeginProperty ColumnHeader(2) {0713E8C7-850A-101B-AFC0-4210102A8DA7} 
  327.             SubItemIndex    =   1
  328.             Key             =   ""
  329.             Object.Tag             =   ""
  330.             Text            =   "Size (bytes)"
  331.             Object.Width           =   1940
  332.          EndProperty
  333.          BeginProperty ColumnHeader(3) {0713E8C7-850A-101B-AFC0-4210102A8DA7} 
  334.             SubItemIndex    =   2
  335.             Key             =   ""
  336.             Object.Tag             =   ""
  337.             Text            =   "Date"
  338.             Object.Width           =   3263
  339.          EndProperty
  340.          BeginProperty ColumnHeader(4) {0713E8C7-850A-101B-AFC0-4210102A8DA7} 
  341.             SubItemIndex    =   3
  342.             Key             =   ""
  343.             Object.Tag             =   ""
  344.             Text            =   ""
  345.             Object.Width           =   0
  346.          EndProperty
  347.       End
  348.    End
  349.    Begin VB.ListBox lstConnectionInfo 
  350.       Height          =   1035
  351.       Left            =   115
  352.       TabIndex        =   0
  353.       TabStop         =   0   'False
  354.       Top             =   5880
  355.       Width           =   12315
  356.    End
  357.    Begin VB.CommandButton cmdSend 
  358.       Height          =   375
  359.       Left            =   5790
  360.       Picture         =   "frmMain.frx":0DD4
  361.       Style           =   1  'Graphical
  362.       TabIndex        =   4
  363.       Top             =   2880
  364.       Width           =   975
  365.    End
  366.    Begin ComctlLib.ImageList lstImageList 
  367.       Left            =   5760
  368.       Top             =   2160
  369.       _ExtentX        =   1005
  370.       _ExtentY        =   1005
  371.       BackColor       =   -2147483643
  372.       ImageWidth      =   16
  373.       ImageHeight     =   16
  374.       MaskColor       =   12632256
  375.       _Version        =   327682
  376.       BeginProperty Images {0713E8C2-850A-101B-AFC0-4210102A8DA7} 
  377.          NumListImages   =   3
  378.          BeginProperty ListImage1 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
  379.             Picture         =   "frmMain.frx":1216
  380.             Key             =   ""
  381.          EndProperty
  382.          BeginProperty ListImage2 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
  383.             Picture         =   "frmMain.frx":1768
  384.             Key             =   ""
  385.          EndProperty
  386.          BeginProperty ListImage3 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
  387.             Picture         =   "frmMain.frx":1CBA
  388.             Key             =   ""
  389.          EndProperty
  390.       EndProperty
  391.    End
  392.    Begin XceedFtpLibCtl.XceedFtp xFtp 
  393.       Left            =   5760
  394.       Top             =   1680
  395.       AccountName     =   ""
  396.       AllocateStorage =   0   'False
  397.       BackgroundProcessing=   0   'False
  398.       CommandLogFilename=   ""
  399.       EventFilter     =   8151
  400.       ListParsingFlags=   1
  401.       LocalDataAddress=   ""
  402.       LocalDataPort   =   0
  403.       PassiveMode     =   -1  'True
  404.       Password        =   "guest"
  405.       RepresentationType=   0
  406.       ServerAddress   =   ""
  407.       ServerPort      =   21
  408.       UserName        =   "anonymous"
  409.       FirewallType    =   0
  410.       FirewallAddress =   ""
  411.       FirewallPort    =   1080
  412.       FirewallUser    =   ""
  413.       FirewallPassword=   ""
  414.    End
  415.    Begin VB.Menu miConnection 
  416.       Caption         =   "Co&nnection"
  417.       Begin VB.Menu miConnect 
  418.          Caption         =   "&Connect..."
  419.       End
  420.       Begin VB.Menu miDisconnect 
  421.          Caption         =   "&Disconnect"
  422.       End
  423.       Begin VB.Menu miAbort 
  424.          Caption         =   "&Abort"
  425.       End
  426.    End
  427.    Begin VB.Menu miTransfer 
  428.       Caption         =   "&Transfer"
  429.       Begin VB.Menu miSend 
  430.          Caption         =   "&Send File(s)"
  431.       End
  432.       Begin VB.Menu miReceive 
  433.          Caption         =   "&Receive File(s)"
  434.       End
  435.    End
  436.    Begin VB.Menu miOperations 
  437.       Caption         =   "&Operations"
  438.       Begin VB.Menu miLocal 
  439.          Caption         =   "&Local"
  440.          Begin VB.Menu miDeleteLocalFile 
  441.             Caption         =   "Delete File(s)"
  442.          End
  443.          Begin VB.Menu miRenameLocalFile 
  444.             Caption         =   "Rename File"
  445.          End
  446.          Begin VB.Menu miCreateLocalFolder 
  447.             Caption         =   "Create Folder"
  448.          End
  449.          Begin VB.Menu miRemoveLocalFolder 
  450.             Caption         =   "Remove Folder"
  451.          End
  452.       End
  453.       Begin VB.Menu miRemote 
  454.          Caption         =   "&Remote"
  455.          Begin VB.Menu miDeleteRemoteFile 
  456.             Caption         =   "Delete File"
  457.          End
  458.          Begin VB.Menu miRenameRemoteFile 
  459.             Caption         =   "Rename File"
  460.          End
  461.          Begin VB.Menu miCreateRemoteFolder 
  462.             Caption         =   "Create Folder"
  463.          End
  464.          Begin VB.Menu miRemoveRemoteFolder 
  465.             Caption         =   "Remove Folder"
  466.          End
  467.       End
  468.    End
  469. Attribute VB_Name = "frmMain"
  470. Attribute VB_GlobalNameSpace = False
  471. Attribute VB_Creatable = False
  472. Attribute VB_PredeclaredId = True
  473. Attribute VB_Exposed = False
  474. ' Xceed FTP Library - FTP Client sample application
  475. ' Copyright (c) 2000 Xceed Software Inc.
  476. ' [FrmXceedFTP.frm]
  477. ' This form module contains code for the main form for the FTP client.
  478. ' This file is part of the Xceed FTP Library sample applications. The source
  479. ' code in this file is only intended as a supplement to Xceed FTP Library's
  480. ' documentation, and is provided "as is", without warranty of any kind,
  481. ' either expressed or implied.
  482. Option Explicit
  483. Dim WithEvents m_xLocalPaths As clsLocalPaths  ' Handles local files (see clsLocalPaths module)
  484. Attribute m_xLocalPaths.VB_VarHelpID = -1
  485. Dim m_xResizer As clsResizer                   ' Handles form resizing (see clsResizer module)
  486. ' Note: The xFtp object is instanciated automatically because there is an XceedFtp object
  487. '       named 'xFtp' that is placed on the main form.
  488. Dim m_sCurrentLocalPath As String              ' Stores current local path
  489. Dim m_sCurrentRemotePath As String             ' Stores current remote path
  490. Dim m_sLastServerAddressUsed As String         ' Keep this information persistent
  491. Dim m_sLastServerPortUsed As String            ' so that when the connection
  492. Dim m_sLastUsernameUsed As String              ' dialog form is shown, user does
  493. Dim m_sLastPasswordUsed As String              ' not have to retype everything
  494. Dim m_bIsAnonymous As Boolean                  ' each time.
  495. Const MsgBoxTitle = "FTP Client sample application "
  496. ' ****************************************************************************
  497. ' Look for character in reverse order.
  498. ' Equivalent to the VB6 InStrRev function.
  499. ' ****************************************************************************
  500. Private Function InStrReverse(ByVal sSource As String, ByVal sLookFor As String, ByVal nStart As Integer) As Integer
  501.     Dim nLen As Integer
  502.     nLen = Len(sSource)
  503.     If nLen = 0 Then
  504.         InStrReverse = 0
  505.     Else
  506.         Dim sReverse As String
  507.         sReverse = Space(nLen)
  508.         Dim i As Integer
  509.         For i = 1 To nLen
  510.             Mid(sReverse, nLen - i + 1, 1) = Mid(sSource, i, 1)
  511.         Next i
  512.         
  513.         InStrReverse = InStr(nLen - nStart + 1, sReverse, sLookFor)
  514.     End If
  515. End Function
  516. ' ****************************************************************************
  517. ' Clear portions of the progress bar for single file operations.
  518. ' ****************************************************************************
  519. Private Sub ClearBars()
  520.   prgStatus.Value = 0
  521.   stbProgress.Panels(2).Text = ""
  522. End Sub
  523. ' ****************************************************************************
  524. ' Delete file(s) from local system
  525. ' ****************************************************************************
  526. Private Sub DeleteSelectedLocalFile()
  527.   Dim xItem As ListItem
  528.   Dim nMsgResult As VbMsgBoxResult
  529.   ' Confirm with the user first
  530.   nMsgResult = MsgBox("Are you sure you want to delete the selected local file(s)?", _
  531.                       vbYesNo + vbQuestion, MsgBoxTitle & "[Confirm]")
  532.                       
  533.   If nMsgResult = vbYes Then
  534.     For Each xItem In lstLocalFileList.ListItems
  535.       If xItem.Selected Then ' Delete the file(s)
  536.         Call m_xLocalPaths.DeleteLocalFile(m_sCurrentLocalPath & xItem.Text)
  537.       End If
  538.     Next xItem
  539.     Call RefreshLocalFileList
  540.   End If
  541. End Sub
  542. ' ****************************************************************************
  543. ' Rename a file on the local system
  544. ' ****************************************************************************
  545. Private Sub RenameLocalFile()
  546.   Dim sNewName As String
  547.   Dim sCurrentName As String
  548.   Dim nMsgResult As VbMsgBoxResult
  549.   sCurrentName = m_sCurrentLocalPath & lstLocalFileList.SelectedItem.Text
  550.   ' Confirm with the user first
  551.   nMsgResult = MsgBox("Rename local file " & sCurrentName & "?", vbYesNo + vbQuestion, MsgBoxTitle & "[Confirm]")
  552.   If nMsgResult = vbYes Then
  553.     sNewName = InputBox("Enter the new name for " & sCurrentName, "Xceed FTP Library - client sample")
  554.     If sNewName <> "" Then ' Rename the file
  555.       Call m_xLocalPaths.RenameLocalFile(sCurrentName, m_sCurrentLocalPath & sNewName)
  556.       Call RefreshLocalFileList
  557.     End If
  558.   End If
  559. End Sub
  560. ' ****************************************************************************
  561. ' Create a new folder on the local system
  562. ' ****************************************************************************
  563. Private Sub CreateLocalFolder()
  564.   Dim sFolderToCreate As String
  565.   ' Query user for new folder's name
  566.   sFolderToCreate = InputBox("Enter the name of the local folder you wish to create.", "Xceed FTP Library - client sample")
  567.   If sFolderToCreate <> "" Then
  568.     Call m_xLocalPaths.CreateLocalFolder(m_sCurrentLocalPath & sFolderToCreate)
  569.     Call RefreshLocalFileList
  570.   End If
  571. End Sub
  572. ' ****************************************************************************
  573. ' Delete a folder from the local system
  574. ' ****************************************************************************
  575. Private Sub DeleteLocalFolder()
  576.   Dim nMsgResult As VbMsgBoxResult
  577.   ' Confirm with the user first
  578.   nMsgResult = MsgBox("Delete " & lstLocalFileList.SelectedItem.Text & "?", vbYesNo + vbQuestion, MsgBoxTitle & "[Confirm]")
  579.   If nMsgResult = vbYes Then
  580.     'Delete the local folder
  581.     Call m_xLocalPaths.RemoveLocalFolder(m_sCurrentLocalPath & lstLocalFileList.SelectedItem.Text)
  582.     Call RefreshLocalFileList
  583.     Call UpdateLocalFilesState
  584.   End If
  585. End Sub
  586. ' ****************************************************************************
  587. ' Delete file(s) from the remote system
  588. ' ****************************************************************************
  589. Private Sub DeleteSelectedRemoteFile()
  590.   Dim nMsgResult As VbMsgBoxResult
  591.   Dim xItem As ListItem
  592.   ' Confirm with the user first
  593.   nMsgResult = MsgBox("Are you sure you want to delete the selected remote file(s)?", _
  594.                       vbYesNo + vbQuestion, MsgBoxTitle & "[Confirm]")
  595.                   
  596.   If nMsgResult = vbYes Then
  597.     For Each xItem In lstRemoteFileList.ListItems       ' For each item in the remote file list
  598.       If xItem.Selected Then                            ' Delete selected file(s) only
  599.         Call xFtp.DeleteFile(xItem.Text)
  600.         stbProgress.Panels(1).Text = ""
  601.       End If
  602.     Next xItem
  603.     Call RefreshRemoteFileList
  604.   End If
  605. End Sub
  606. ' ****************************************************************************
  607. ' Rename a file on the remote server
  608. ' ****************************************************************************
  609. Private Sub RenameRemoteFile()
  610.   Dim sNewName As String
  611.   Dim nMsgResult As VbMsgBoxResult
  612.   ' Confirm with the user first
  613.   nMsgResult = MsgBox("Rename remote file " & lstRemoteFileList.SelectedItem.Text & "?", vbYesNo + vbQuestion, MsgBoxTitle & "[Confirm]")
  614.   If nMsgResult = vbYes Then ' Get new filename from user, then rename it
  615.     sNewName = InputBox("Rename remote file to : ", "Xceed FTP Library - client sample")
  616.     Call xFtp.RenameFile(lstRemoteFileList.SelectedItem.Text, sNewName)
  617.     stbProgress.Panels(1).Text = ""
  618.     Call RefreshRemoteFileList
  619.   End If
  620. End Sub
  621. ' ****************************************************************************
  622. ' Create a new folder on the remote server
  623. ' ****************************************************************************
  624. Private Sub CreateRemoteFolder()
  625.   Dim sFolderToCreate As String
  626.   ' Query user for new folder's name
  627.   sFolderToCreate = InputBox("Enter the name of the folder you want to create.", "Xceed FTP Library - client sample")
  628.   Call xFtp.CreateFolder(sFolderToCreate)
  629.   stbProgress.Panels(1).Text = ""
  630.   Call RefreshRemoteFileList
  631. End Sub
  632. ' ****************************************************************************
  633. ' Delete a folder on the remote server
  634. ' ****************************************************************************
  635. Private Sub DeleteRemoteFolder()
  636.   Dim nMsgResult As VbMsgBoxResult
  637.   ' Confirm with the user first
  638.   nMsgResult = MsgBox("Delete " & lstRemoteFileList.SelectedItem.Text & "?", vbYesNo + vbQuestion, MsgBoxTitle & "[Confirm]")
  639.   If nMsgResult = vbYes Then
  640.     'Delete the remote folder
  641.     Call xFtp.RemoveFolder(lstRemoteFileList.SelectedItem.Text)
  642.     stbProgress.Panels(1).Text = ""
  643.     Call RefreshRemoteFileList
  644.   End If
  645. End Sub
  646. ' ****************************************************************************
  647. ' The following procedure will open the connection dialog box so that
  648. ' the user can enter the information necessary in order to connect to an
  649. ' FTP server.
  650. ' ****************************************************************************
  651. Private Sub Connect()
  652.   ' Show that the main form is no longer accepting commands
  653.   Me.MousePointer = vbHourglass
  654.   cboRemotePath.Tag = 1 ' Doing this will prevent the "click" event of the combo box from being triggered.
  655.   ' Load the frmConnectionInfo dialog box
  656.   Load frmConnectionInfo
  657.   ' Call the connection dialog form's ShowForm function and check the
  658.   ' result. If True, the user requested to Connect. False mans they cancelled out.
  659.   If frmConnectionInfo.ShowForm(m_sLastServerAddressUsed, m_sLastServerPortUsed, m_sLastUsernameUsed, m_sLastPasswordUsed, m_bIsAnonymous) Then
  660.     ' We don't need that connection form anymore
  661.     Unload frmConnectionInfo
  662.     ' Assign the variables which may have changed to the XceedFtp object's
  663.     ' corresponding properties
  664.     xFtp.ServerAddress = m_sLastServerAddressUsed
  665.     xFtp.ServerPort = m_sLastServerPortUsed
  666.     If m_bIsAnonymous Then
  667.       xFtp.UserName = "anonymous"            ' Common username for anonymous login
  668.       xFtp.Password = "guest"                ' Common password for anonymous login
  669.     Else
  670.       xFtp.UserName = m_sLastUsernameUsed
  671.       xFtp.Password = m_sLastPasswordUsed
  672.     End If
  673.     ' Tell the XceedFtp object to connect to the remote FTP server.
  674.     Call ConnectToFtpServer
  675.     ' If connected, let's update some displayed data and enable the remote operation buttons
  676.     If xFtp.CurrentState = fstConnected Then
  677.       Call ListFilesOnServer                 ' List the files in the current remote folder
  678.       Call UpdateConnectionState(True)       ' Enable buttons
  679.     End If
  680.   Else ' User cancelled out from connection dialog form. We don't need that form anymore.
  681.     Unload frmConnectionInfo
  682.   End If
  683.   ' Show that the main form is ready to accept commands again
  684.   Me.MousePointer = vbDefault
  685.   cboRemotePath.Tag = 0
  686. End Sub
  687. ' ****************************************************************************
  688. ' This procedure tells the XceedFtp object to connect to the FTP server. The
  689. ' property values for the server address, port, username and password should
  690. ' allready be set before calling this procedure
  691. ' ****************************************************************************
  692. Private Sub ConnectToFtpServer()
  693.   ' Connect only if not already connected!
  694.   If xFtp.CurrentState = fstNotConnected Then
  695.     On Error GoTo LocalError
  696.     stbProgress.Panels(1).Text = "Connecting to " & xFtp.ServerAddress & ". Please wait..."
  697.     Call xFtp.Connect                      ' Connect to the FTP server
  698.     ' Get the current remote working folder
  699.     m_sCurrentRemotePath = GetRemoteFolder
  700.     ' Add the path to the remote paths combo box
  701.     cboRemotePath.Text = m_sCurrentRemotePath
  702.         
  703.     ' Display connection success
  704.         
  705.     stbProgress.Panels(1).Text = "Connected to " & xFtp.ServerAddress
  706.     Exit Sub
  707.   End If
  708. LocalError:
  709.   Call frmMain.DisplayMessage("Error: " & Err.Description)
  710.   Call frmMain.UpdateAction("")
  711. End Sub
  712. ' ****************************************************************************
  713. ' This procedure calls the XceedFtp object's disconnect method to disconnect
  714. ' from the FTP server. Any currently running command will be aborted first.
  715. ' ****************************************************************************
  716. Private Sub Disconnect()
  717.   ' If current state is other than connected or not connected, that means
  718.   ' there is an operation currently running and we should abort it first.
  719.       
  720.   If (xFtp.CurrentState <> fstNotConnected) And (xFtp.CurrentState <> fstConnected) Then
  721.     xFtp.Abort = True
  722.     While (xFtp.CurrentState <> fstNotConnected) And (xFtp.CurrentState <> fstConnected)
  723.         DoEvents
  724.     Wend
  725.   End If
  726.   ' If we get here, there are no commands running. Disconnect only if connected.
  727.   If xFtp.CurrentState <> fstNotConnected Then
  728.     Call xFtp.Disconnect
  729.   End If
  730. End Sub
  731. ' ****************************************************************************
  732. ' This procedure will send one or more of the currently selected files.
  733. ' For each selected item, this procedure checks to see if it is a folder or
  734. ' a file. If it is a folder, the entire folder's contents are sent by using
  735. ' the XceedFtp object's SendMultipleFiles method. If the selected item is
  736. ' a file, it is sent using the SendFile method.
  737. ' ****************************************************************************
  738. Private Sub SendFiles()
  739.   Dim xItem As ListItem
  740.   Dim nMsgResult As VbMsgBoxResult
  741.   Dim sLocalPath As String
  742.       
  743.   On Error GoTo LocalError
  744.   Me.MousePointer = vbHourglass                        ' Show that we are busy
  745.   Call UpdateAbortButtonState(True)                    ' Allow abort button to be clicked
  746.   For Each xItem In lstLocalFileList.ListItems
  747.     If xItem.Selected Then                             ' Process only selected items
  748.       
  749.       Call ClearBars                                   ' Clear the progress and the status bars
  750.       sLocalPath = m_sCurrentLocalPath & xItem.Text    ' Construct item's complete path
  751.       
  752.       If xItem.SmallIcon = 2 Then                      ' Selected item is a folder
  753.         
  754.         ' Folders are uploaded by using the * wildcard with the SendMultipleFiles
  755.         ' method. We query the user to find out if the library should apply
  756.         ' the * wildcard recursively or not.
  757.         
  758.         nMsgResult = MsgBox("Do you want to send any subfolders that are contained in the '" & sLocalPath & "' folder?", vbYesNo + vbQuestion, MsgBoxTitle & "[Confirm]")
  759.             
  760.         If nMsgResult = vbYes Then                      ' Yes, send subfolders
  761.           Call xFtp.SendMultipleFiles(sLocalPath & "\*", xFtp.CurrentFolder & "\" & xItem.Text, True, True)
  762.         Else                                            ' Do not send subfolders
  763.           Call xFtp.SendMultipleFiles(sLocalPath & "\*", xFtp.CurrentFolder & "\" & xItem.Text, True, False)
  764.         End If
  765.         
  766.       Else                                              ' The selected item is a file
  767.       
  768.         'Upload this item separately. If file exists, we'll append to it.
  769.         
  770.         Call xFtp.SendFile(sLocalPath, 0, xItem.Text, True)
  771.       
  772.       End If
  773.     End If
  774.   Next xItem
  775.   Call UpdateAction("Upload complete") ' Display in the status bar that the process is complete
  776. Cleanup:
  777.   Me.MousePointer = vbDefault
  778.   Call UpdateAbortButtonState(False)
  779.   Call RefreshRemoteFileList
  780.   Exit Sub
  781. LocalError:
  782.   Call DisplayMessage("Error: " & Err.Description)
  783.   GoTo Cleanup
  784. End Sub
  785. ' ****************************************************************************
  786. ' This procedure will receive the selected files or folders from the FTP
  787. ' server. For folders, the procedure uses the XceedFtp object's
  788. ' ReceiveMultipleFiles method. For files, it uses the ReceiveFile method.
  789. ' ****************************************************************************
  790. Private Sub ReceiveFiles()
  791.   Dim xItem As ListItem
  792.   Dim nMsgResult As VbMsgBoxResult
  793.   On Error GoTo LocalError
  794.   Me.MousePointer = vbHourglass                        ' Show that we are busy
  795.   Call UpdateAbortButtonState(True)                    ' Allow abort button to be clicked
  796.   For Each xItem In lstRemoteFileList.ListItems
  797.     If xItem.Selected Then                             ' Process only selected items
  798.       Call ClearBars                                   ' Clear the progress and status bars
  799.       
  800.       ' Add the remote folder name to the local destination
  801.       
  802.       If xItem.SmallIcon = 2 Then                      ' Selected item is a folder
  803.       
  804.         ' Receive the contents of the folder by using the * wildcard and the
  805.         ' ReceiveMultipleFiles method. We query the user to find out if the
  806.         ' library should apply the * wildcard recursively or not.
  807.         
  808.         nMsgResult = MsgBox("Do you want to receive any subfolders that are contained in the '" & xItem.Text & "' folder?", vbYesNo + vbQuestion, MsgBoxTitle & "[Confirm]")
  809.         If nMsgResult = vbYes Then                     ' Receive subfolders
  810.           Call xFtp.ReceiveMultipleFiles(xItem.Text & "\*", m_sCurrentLocalPath, True)
  811.         Else                                           ' Do not receive subfolders
  812.           Call xFtp.ReceiveMultipleFiles(xItem.Text & "\*", m_sCurrentLocalPath, False)
  813.         End If
  814.         
  815.       Else                                             ' Receive this item separately
  816.         Call xFtp.ReceiveFile(xItem.Text, 0, m_sCurrentLocalPath & xItem.Text)
  817.       End If
  818.       
  819.     End If
  820.   Next xItem
  821.   Call UpdateAction("Download complete")  ' 'Update status panel to show that the process is complete
  822. Cleanup:
  823.   Me.MousePointer = vbDefault
  824.   Call UpdateAbortButtonState(False)
  825.   Call RefreshLocalFileList
  826.   Exit Sub
  827. LocalError:
  828.   Call DisplayMessage("Error: " & Err.Description)
  829.   GoTo Cleanup
  830. End Sub
  831. ' ****************************************************************************
  832. ' Clear the contents of the local file list ListView control.
  833. ' ****************************************************************************
  834. Private Sub ClearLocalFileList()
  835.   Call lstLocalFileList.ListItems.Clear
  836. End Sub
  837. ' ****************************************************************************
  838. ' Clear the contents of the remote file list ListView control.
  839. ' ****************************************************************************
  840. Private Sub ClearRemoteFileList()
  841.   Call lstRemoteFileList.ListItems.Clear
  842. End Sub
  843. ' ****************************************************************************
  844. ' This procedure verifies that a path does not already exist in the path list
  845. ' combo box. It returns True is the path exists, False if not. The second
  846. ' parameter of this procedure requires the combo box object to be searched.
  847. ' ****************************************************************************
  848. Private Function ComboPathExists(ByVal sPathToCheck As String, CB As ComboBox) As Boolean
  849.   Dim nCount As Integer
  850.   nCount = 0
  851.   ComboPathExists = False
  852.   While nCount < CB.ListCount
  853.     If UCase(sPathToCheck) = CB.List(nCount) Then      ' The specified path exists!
  854.       ComboPathExists = True
  855.       nCount = CB.ListCount
  856.     Else
  857.       nCount = nCount + 1
  858.     End If
  859.   Wend
  860. End Function
  861. ' ****************************************************************************
  862. ' Refresh the local file list ListView control and display the new contents by
  863. ' calling the RetreiveLocalFolderContents procedure in the clsLocalPaths class.
  864. ' ****************************************************************************
  865. Private Sub RefreshLocalFileList()
  866.   Call ClearLocalFileList
  867.   Call m_xLocalPaths.RetrieveLocalFolderContents(m_sCurrentLocalPath)
  868. End Sub
  869. ' ****************************************************************************
  870. ' Refresh the remote file list ListView control and display the new contents by
  871. ' calling the ListFilesOnServer procedure. This might take some time, so we
  872. ' set the mouse cursor to "wait" until the operation is completed.
  873. ' ****************************************************************************
  874. Private Sub RefreshRemoteFileList()
  875.   ' Setup GUI for long operation
  876.   Me.MousePointer = vbHourglass
  877.   Call ClearRemoteFileList
  878.   Call UpdateAbortButtonState(True)
  879.   Call ListFilesOnServer
  880.   ' Reset GUI back to normal
  881.   Call UpdateAbortButtonState(False)
  882.   stbProgress.Panels(1).Text = ""
  883.   Me.MousePointer = vbDefault
  884. End Sub
  885. ' ****************************************************************************
  886. ' This function returns the number of selected items in a ListView. A
  887. ' reference to the ListView control must be passed by parameter.
  888. ' ****************************************************************************
  889. Private Function CountSelectedItems(LV As ListView) As Long
  890.   Dim xItem As ListItem
  891.   Dim nCount As Integer
  892.   nCount = 0
  893.       
  894.   For Each xItem In LV.ListItems
  895.     If xItem.Selected Then
  896.       nCount = nCount + 1
  897.     End If
  898.   Next xItem
  899.           
  900.   CountSelectedItems = nCount
  901. End Function
  902. ' ****************************************************************************
  903. ' This procedure enables or disables some of the form's controls depending
  904. ' on the current connection state. The connection state is passed by parameter.
  905. ' ****************************************************************************
  906. Private Sub UpdateConnectionState(ByVal bConnected As Boolean)
  907.   cmdDisconnect.Enabled = bConnected
  908.   cmdUpFtp.Enabled = bConnected
  909.   ' Some items need to be activated as soon as we are connected
  910.   cmdCreateRemoteFolder.Enabled = bConnected
  911.   miCreateRemoteFolder.Enabled = bConnected
  912.   optAscii.Enabled = bConnected
  913.   optBinary.Enabled = bConnected
  914.   ' If we are not connected, we do not want to give the user the option to send files
  915.   cmdSend.Enabled = bConnected
  916.   miSend.Enabled = bConnected
  917.   cboRemotePath.Enabled = bConnected
  918.   miDisconnect.Enabled = bConnected
  919.   miTransfer.Enabled = bConnected
  920.   miRemote.Enabled = bConnected
  921.   ' We want the connect button (and menu) to be disabled if we are connected
  922.   cmdConnect.Enabled = Not bConnected
  923.   miConnect.Enabled = Not bConnected
  924. End Sub
  925. ' ****************************************************************************
  926. ' This procedure updates the state of the abort button and the abort menu item.
  927. ' ****************************************************************************
  928. Private Sub UpdateAbortButtonState(ByVal bEnabled As Boolean)
  929.   cmdAbort.Enabled = bEnabled
  930.   miAbort.Enabled = bEnabled
  931. End Sub
  932. ' ****************************************************************************
  933. ' Update the state of the buttons and menus for remote file/folder operations.
  934. ' The button states depend largely on the number and type of items selected
  935. ' in the remote file list ListView object.
  936. ' ****************************************************************************
  937. Private Sub UpdateRemoteFilesState()
  938.   Dim bMultipleSelected As Boolean
  939.   Dim bFileListIsNothing As Boolean
  940.   Dim nTypeOfItemSelected As Integer
  941.   ' If nothing is selected, then all items will be disabled
  942.   bFileListIsNothing = lstRemoteFileList.SelectedItem Is Nothing
  943.   ' If something is selected, cound the amount of selected items, and check
  944.   ' store their type (file, folder or link) in the nTypeOfItemsSelected variable
  945.   If Not bFileListIsNothing Then
  946.     bMultipleSelected = CountSelectedItems(lstRemoteFileList) > 1
  947.     If Not bMultipleSelected Then
  948.        nTypeOfItemSelected = lstRemoteFileList.SelectedItem.SmallIcon
  949.     Else
  950.        nTypeOfItemSelected = 0
  951.     End If
  952.   End If
  953.   ' Now set the button states depending on the number and type of items selected
  954.   cmdDeleteRemoteFile.Enabled = (Not bFileListIsNothing) And ((bMultipleSelected) Or (nTypeOfItemSelected = 1)) ' Many items, or one if it is a file
  955.   miDeleteRemoteFile.Enabled = cmdDeleteRemoteFile.Enabled
  956.   cmdRenameRemoteFile.Enabled = (Not bFileListIsNothing) And (nTypeOfItemSelected = 1) ' One item selected: its a file
  957.   miRenameRemoteFile.Enabled = cmdRenameRemoteFile.Enabled
  958.   cmdDeleteRemoteFolder.Enabled = (Not bFileListIsNothing) And (nTypeOfItemSelected = 2) ' One item selected: its a folder
  959.   miRemoveRemoteFolder.Enabled = cmdDeleteRemoteFolder.Enabled
  960.   cmdReceive.Enabled = (Not bFileListIsNothing) And (CountSelectedItems(lstRemoteFileList) > 0) ' One or more files selected
  961.   miReceive.Enabled = cmdReceive.Enabled
  962. End Sub
  963. ' ****************************************************************************
  964. ' Update the state of the buttons and menus for local file/folder operations.
  965. ' The button states depend largely on the number and type of items selected
  966. ' in the remote file list ListView object.
  967. ' ****************************************************************************
  968. Private Sub UpdateLocalFilesState()
  969.   Dim bMultipleSelected As Boolean
  970.   Dim bFileListIsNothing As Boolean
  971.   Dim nTypeOfItemSelected As Integer
  972.   ' If nothing is selected, then all items will be disabled
  973.   bFileListIsNothing = lstLocalFileList.SelectedItem Is Nothing ' if yes, everything is false
  974.   ' If something is selected, cound the amount of selected items, and check
  975.   ' store their type (file, folder or link) in the nTypeOfItemsSelected variable
  976.   If Not bFileListIsNothing Then
  977.     bMultipleSelected = CountSelectedItems(lstLocalFileList) > 1
  978.     If Not bMultipleSelected Then
  979.        nTypeOfItemSelected = lstLocalFileList.SelectedItem.SmallIcon
  980.     Else
  981.        nTypeOfItemSelected = 0
  982.     End If
  983.   End If
  984.   ' Now set the button states depending on the number and type of items selected
  985.   cmdDeleteLocalFile.Enabled = (Not bFileListIsNothing) And ((bMultipleSelected) Or (nTypeOfItemSelected = 1)) ' Many items, or one if it is a file
  986.   miDeleteLocalFile.Enabled = cmdDeleteLocalFile.Enabled
  987.   cmdRenameLocalFile.Enabled = (Not bFileListIsNothing) And (nTypeOfItemSelected = 1) ' One item selected: its a file
  988.   miRenameLocalFile.Enabled = cmdRenameLocalFile.Enabled
  989.   cmdCreateLocalFolder.Enabled = True ' At all times, connected or not!
  990.   miCreateLocalFolder.Enabled = cmdCreateLocalFolder.Enabled
  991.   cmdRemoveLocalFolder.Enabled = (Not bFileListIsNothing) And (nTypeOfItemSelected = 2) ' One item selected: its a folder
  992.   miRemoveLocalFolder.Enabled = cmdRemoveLocalFolder.Enabled
  993.   cmdSend.Enabled = (Not bFileListIsNothing) And (CountSelectedItems(lstLocalFileList) > 0) And (xFtp.CurrentState = fstConnected) ' One or more files selected
  994.   miSend.Enabled = cmdSend.Enabled
  995. End Sub
  996. ' ****************************************************************************
  997. ' List the current remote folder's contents using the XceedFtp object's
  998. ' ListFolderContents method. The ListingFolderItem event will be triggered
  999. ' by the library in order to allow this sample application to obtain and
  1000. ' display the items in our remote file list ListView control.
  1001. ' ****************************************************************************
  1002. Public Sub ListFilesOnServer()
  1003.   On Error GoTo LocalError
  1004.   ' We will let the Xceed FTP Library parse the FTP server's folder listing for us.
  1005.   xFtp.ListParsingFlags = flpAutomaticParsing
  1006.   Call UpdateAction("Obtaining directory listing...") ' Display note on status bar
  1007.   ' Start obtaining the folder listing (will trigger the ListingFolderItem event
  1008.   ' for each listed item)
  1009.   Call xFtp.ListFolderContents("")
  1010.   Exit Sub
  1011. LocalError:
  1012.   Call DisplayMessage("Error: " & Err.Description)
  1013. End Sub
  1014. ' ****************************************************************************
  1015. ' The following procedures are event handlers for button click events
  1016. ' ****************************************************************************
  1017. Private Sub cmdDeleteLocalFile_Click()
  1018.   Call DeleteSelectedLocalFile
  1019. End Sub
  1020. Private Sub cmdRenameLocalFile_Click()
  1021.   Call RenameLocalFile
  1022. End Sub
  1023. Private Sub cmdCreateLocalFolder_Click()
  1024.   Call CreateLocalFolder
  1025. End Sub
  1026. Private Sub cmdRemoveLocalFolder_Click()
  1027.   Call DeleteLocalFolder
  1028. End Sub
  1029. Private Sub cmdDeleteRemoteFile_Click()
  1030.   Call DeleteSelectedRemoteFile
  1031. End Sub
  1032. Private Sub cmdRenameRemoteFile_Click()
  1033.   Call RenameRemoteFile
  1034. End Sub
  1035. Private Sub cmdCreateRemoteFolder_Click()
  1036.   Call CreateRemoteFolder
  1037. End Sub
  1038. Private Sub cmdDeleteRemoteFolder_Click()
  1039.   Call DeleteRemoteFolder
  1040. End Sub
  1041. Private Sub cmdConnect_Click()
  1042.   Call Connect
  1043. End Sub
  1044. Private Sub cmdDisconnect_Click()
  1045.   Call Disconnect
  1046. End Sub
  1047. Private Sub cmdSend_Click()
  1048.   Call SendFiles
  1049. End Sub
  1050. Private Sub cmdReceive_Click()
  1051.   Call ReceiveFiles
  1052. End Sub
  1053. Private Sub cmdAbort_Click()
  1054.   Call Abort
  1055. End Sub
  1056. Private Sub miAbort_Click()
  1057.   Call Abort
  1058. End Sub
  1059. Private Sub miDeleteLocalFile_Click()
  1060.   Call DeleteSelectedLocalFile
  1061. End Sub
  1062. Private Sub miRenameLocalFile_Click()
  1063.   Call RenameLocalFile
  1064. End Sub
  1065. Private Sub miCreateLocalFolder_Click()
  1066.   Call CreateLocalFolder
  1067. End Sub
  1068. Private Sub miRemoveLocalFolder_Click()
  1069.   Call DeleteLocalFolder
  1070. End Sub
  1071. Private Sub miDeleteRemoteFile_Click()
  1072.   Call DeleteSelectedRemoteFile
  1073. End Sub
  1074. Private Sub miRenameRemoteFile_Click()
  1075.   Call RenameRemoteFile
  1076. End Sub
  1077. Private Sub miCreateRemoteFolder_Click()
  1078.   Call CreateRemoteFolder
  1079. End Sub
  1080. Private Sub miRemoveRemoteFolder_Click()
  1081.   Call DeleteRemoteFolder
  1082. End Sub
  1083. Private Sub miConnect_Click()
  1084.   Call Connect
  1085. End Sub
  1086. Private Sub miDisconnect_Click()
  1087.   Call Disconnect
  1088. End Sub
  1089. Private Sub miSend_Click()
  1090.   Call SendFiles
  1091. End Sub
  1092. Private Sub miReceive_Click()
  1093.   Call ReceiveFiles
  1094. End Sub
  1095. Private Sub optAscii_Click()
  1096.   xFtp.RepresentationType = frtASCII
  1097. End Sub
  1098. Private Sub optBinary_Click()
  1099.   xFtp.RepresentationType = frtBinary 'Binary (default)
  1100. End Sub
  1101. ' ****************************************************************************
  1102. ' When a path is selected from the local paths combo box, this procedure is
  1103. ' triggered to update the contents of the local file list ListView control
  1104. ' ****************************************************************************
  1105. Private Sub cboLocalPath_Click()
  1106.   Dim sPath As String
  1107.   sPath = cboLocalPath.List(cboLocalPath.ListIndex)
  1108.   Call ClearLocalFileList
  1109.   Call m_xLocalPaths.RetrieveLocalFolderContents(sPath)
  1110.   m_sCurrentLocalPath = sPath
  1111. End Sub
  1112. ' ****************************************************************************
  1113. ' When a path is selected from the remote paths combo box, this procedure is
  1114. ' triggered to update the contents of the remote file list ListView control
  1115. ' ****************************************************************************
  1116. Private Sub cboRemotePath_Click()
  1117.   Dim sPath As String
  1118.   sPath = cboRemotePath.List(cboRemotePath.ListIndex)
  1119.   If cboRemotePath.Tag = 0 Then 'We do not want the combo box's "click" event to be triggered
  1120.     Call ChangeCurrentRemoteFolder(sPath, True)
  1121.     Call ClearRemoteFileList
  1122.     Call UpdateAbortButtonState(True)
  1123.     Call ListFilesOnServer
  1124.     Call UpdateAbortButtonState(False)
  1125.     stbProgress.Panels(1).Text = ""
  1126.   End If
  1127.   m_sCurrentRemotePath = sPath
  1128. End Sub
  1129. ' ****************************************************************************
  1130. ' Folder up button. Changes the current local folder to its parent folder and
  1131. ' lists the contents of the parent folder.
  1132. ' ****************************************************************************
  1133. Private Sub cmdUpLocal_Click()
  1134.   Dim sNewCurrentLocalPath As String
  1135.   Dim i As Integer
  1136.   If Len(m_sCurrentLocalPath) > 3 Then 'only if the path is not the root
  1137.     i = InStrReverse(m_sCurrentLocalPath, "\", Len(m_sCurrentLocalPath) - 1)
  1138.     sNewCurrentLocalPath = Mid(m_sCurrentLocalPath, 1, i)
  1139.     Call ClearLocalFileList
  1140.     Call m_xLocalPaths.RetrieveLocalFolderContents(sNewCurrentLocalPath)
  1141.     m_sCurrentLocalPath = sNewCurrentLocalPath ' Change to the new current path
  1142.     ' Set the text of the local path selection combo box to the new current path
  1143.     cboLocalPath.Text = UCase(m_sCurrentLocalPath)
  1144.     Call UpdateLocalFilesState
  1145.   End If
  1146. End Sub
  1147. ' ****************************************************************************
  1148. ' This function returns the current remote folder (the XceedFtp object's
  1149. ' CurrentFoldre property is consulted) but also adds the path to the remote
  1150. ' folder listing combo box.
  1151. ' ****************************************************************************
  1152. Public Function GetRemoteFolder() As String
  1153.   On Error GoTo LocalError
  1154.   GetRemoteFolder = xFtp.CurrentFolder
  1155.   ' We will send the new path information to our main form to add it to our combo box
  1156.   Call AddToRemotePaths(GetRemoteFolder)
  1157.   Exit Function
  1158. LocalError:
  1159.   Call DisplayMessage("Error: " & Err.Description)
  1160. End Function
  1161. ' ****************************************************************************
  1162. ' Change the current remote folder to the new one specifed by the user.
  1163. ' ****************************************************************************
  1164. Public Function ChangeCurrentRemoteFolder(ByVal sNewCurrentFolder As String, ByVal bShowErrors As Boolean) As Boolean
  1165.   On Error GoTo LocalError
  1166.   ChangeCurrentRemoteFolder = False
  1167.           
  1168.   Call xFtp.ChangeCurrentFolder(sNewCurrentFolder)  ' Change the current remote folder
  1169.   ChangeCurrentRemoteFolder = True                    ' We successfully changed folders
  1170.   Call GetRemoteFolder                                ' Set the new current local folder
  1171.   Exit Function
  1172. LocalError:
  1173.   If bShowErrors Then
  1174.     Call DisplayMessage("Error: " & Err.Description)
  1175.   End If
  1176. End Function
  1177. ' ****************************************************************************
  1178. ' Abort the current operation (Sets the XceedFtp object's Abort property)
  1179. ' ****************************************************************************
  1180. Public Sub Abort()
  1181.   On Error Resume Next
  1182.   xFtp.Abort = True ' Abort the current operation
  1183.   If Err.Number <> 0 Then
  1184.     MsgBox "Cannot abort the current operation! Error: " & vbCrLf & Err.Description & Err.Number, vbOKCancel + vbExclamation, MsgBoxTitle & "[Notice]"""
  1185.     Err.Clear
  1186.   End If
  1187. End Sub
  1188. ' ****************************************************************************
  1189. ' Changes the current remote folder to its parent folder and lists the contents
  1190. ' of the parent folder
  1191. ' ****************************************************************************
  1192. Private Sub cmdUpFtp_Click()
  1193.   Call xFtp.ChangeToParentFolder
  1194.   m_sCurrentRemotePath = GetRemoteFolder
  1195.   Call ClearRemoteFileList
  1196.   Call UpdateAbortButtonState(True)
  1197.   Call ListFilesOnServer
  1198.   Call UpdateAbortButtonState(False)
  1199.   Call UpdateRemoteFilesState
  1200.   stbProgress.Panels(1).Text = ""
  1201.   ' Set the text of the remote combo box to the new current path
  1202.   cboRemotePath.Text = m_sCurrentRemotePath
  1203. End Sub
  1204. Private Sub Form_Load()
  1205.   Set m_xLocalPaths = New clsLocalPaths     ' Create an instance of the clsLocalPaths class
  1206.   Set m_xResizer = New clsResizer           ' Create an instance of the clsResizer class
  1207.   optBinary.Value = True                    ' Set default transfer type to Binary
  1208.   ' Add some suggestions by default for the connection dialog box
  1209.   m_sLastServerAddressUsed = "ftp.cdrom.com"
  1210.   m_sLastServerPortUsed = "21"
  1211.   m_sLastUsernameUsed = ""
  1212.   m_sLastPasswordUsed = ""
  1213.   m_bIsAnonymous = True
  1214.   ' Update the local and remote ListView object state (and the associated button states)
  1215.   Call UpdateLocalFilesState
  1216.   Call UpdateRemoteFilesState
  1217.   Call UpdateConnectionState(False)
  1218.   Call UpdateAbortButtonState(False)
  1219.   Call m_xLocalPaths.RetreiveLogicalDrives  ' Get the logical drives
  1220.   m_sCurrentLocalPath = "C:\"               ' Set the current local path
  1221.   ' Set the text of the local path selection combo box to the current path.
  1222.   cboLocalPath.Text = m_sCurrentLocalPath
  1223.   ' Retrieve the contents of the current local path and display them
  1224.   Call m_xLocalPaths.RetrieveLocalFolderContents(m_sCurrentLocalPath)
  1225.   Call m_xResizer.PrepareClass(Me)  'Prepare the clsResizer class
  1226. End Sub
  1227. ' ****************************************************************************
  1228. ' If form is resized, tell our resizer class instance to do its job
  1229. ' ****************************************************************************
  1230. Private Sub Form_Resize()
  1231.   Call m_xResizer.ResizeControls  ' Resize the controls
  1232. End Sub
  1233. ' ****************************************************************************
  1234. ' Before form unloads, make sure we are disconnected and free any memory
  1235. ' or classes we have allocated or instanciated
  1236. ' ****************************************************************************
  1237. Private Sub Form_Unload(Cancel As Integer)
  1238.   Call Disconnect                 ' Disconnect if currently connected
  1239.   Set m_xLocalPaths = Nothing     ' Destroy our instance of the clsLocalPaths class
  1240.   Set m_xResizer = Nothing        ' Destroy our instance of the clsResizer class
  1241. End Sub
  1242. ' ****************************************************************************
  1243. ' Enable or disable the local file operation buttons depending on which items
  1244. ' are selected in the local file list ListView control.
  1245. ' ****************************************************************************
  1246. Private Sub lstLocalFileList_Click()
  1247.   Call UpdateLocalFilesState
  1248. End Sub
  1249. ' ****************************************************************************
  1250. ' Double clicking on a file in the local list has two possible results. If the
  1251. ' selected item is a file, this procedure will send the file. If the selected
  1252. ' item is a folder, this procedure will change the current local folder to the
  1253. ' selected folder and then list its contents.
  1254. ' ****************************************************************************
  1255. Private Sub lstLocalFileList_DblClick()
  1256.   Dim nAttrib As Integer
  1257.   Dim sSelectedItem As String
  1258.   Dim nMsgResult As VbMsgBoxResult
  1259.   If lstLocalFileList.SelectedItem.SmallIcon = 1 Then ' Selected item is a file, send it!
  1260.     'Make sure that we don't try sending a file if we aren't even connected!
  1261.     If xFtp.CurrentState <> fstNotConnected Then
  1262.       nMsgResult = MsgBox("Upload file '" & lstLocalFileList.SelectedItem.Text & "'?", vbYesNo + vbQuestion, MsgBoxTitle & "[Confirm]")
  1263.     End If
  1264.     If nMsgResult = vbYes Then
  1265.       Call SendFiles
  1266.     End If
  1267.   Else  ' Selected item is a folder, so we'll change our current folder to that
  1268.     sSelectedItem = m_sCurrentLocalPath & lstLocalFileList.SelectedItem.Text & "\"
  1269.     Call ClearLocalFileList
  1270.     Call m_xLocalPaths.RetrieveLocalFolderContents(sSelectedItem) ' List contents of a new folder
  1271.     Call UpdateLocalFilesState
  1272.     m_sCurrentLocalPath = sSelectedItem
  1273.   End If
  1274. End Sub
  1275. ' ****************************************************************************
  1276. ' Enable or disable the local controls depending on the items selected in the
  1277. ' remote file list ListView control.
  1278. ' ****************************************************************************
  1279. Private Sub lstRemoteFileList_Click()
  1280.   Call UpdateRemoteFilesState
  1281. End Sub
  1282. ' ****************************************************************************
  1283. ' The items in the remote file list ListView control can be either files,
  1284. ' folders or links.
  1285. ' If the selected item is a file, then the ReceiveFiles procedure will be called.
  1286. ' If it is a folder, then the current remote folder will be changed and the new
  1287. ' contents will be listed.
  1288. ' If the item is a link, then it can either link to a file or a folder. Since
  1289. ' we do not have a way of determining beforehand if it is a file or a folder,
  1290. ' we will first assume that it links to a folder and try to change the current
  1291. ' remote folder. If this is successful, then we will list the contents of the
  1292. ' new current remote folder. If this fails, we will consider the link to be
  1293. ' a file and call the ReceiveFiles method.
  1294. ' ****************************************************************************
  1295. Private Sub lstRemoteFileList_DblClick()
  1296.   Dim sSelectedItem As String
  1297.   cboRemotePath.Tag = 1                    ' Don't react to the click event anymore
  1298.   If xFtp.CurrentState = fstConnected Then ' Do something only if we are connected
  1299.     sSelectedItem = lstRemoteFileList.SelectedItem.Text
  1300.     Select Case lstRemoteFileList.SelectedItem.SmallIcon
  1301.     Case 1                                 ' Selected item is a file
  1302.       Call ReceiveFiles
  1303.       
  1304.     Case 2                                 'Selected item is a folder
  1305.       Call ChangeCurrentRemoteFolder(sSelectedItem, True)
  1306.       m_sCurrentRemotePath = GetRemoteFolder
  1307.       Call ClearRemoteFileList
  1308.       Call UpdateAbortButtonState(True)
  1309.       Call ListFilesOnServer
  1310.       Call UpdateAbortButtonState(False)
  1311.       Call UpdateRemoteFilesState
  1312.       stbProgress.Panels(1).Text = ""
  1313.     Case 3                                 ' Selected item is a link
  1314.       
  1315.       ' We will first try to change the current remote folder to see
  1316.       ' if the link is a link to a folder. If that fails then we will
  1317.       ' just download the file the link is pointing to.
  1318.       
  1319.       If ChangeCurrentRemoteFolder(sSelectedItem, False) Then ' Try changing the current remote folder
  1320.         m_sCurrentRemotePath = GetRemoteFolder
  1321.         Call ClearRemoteFileList
  1322.         Call UpdateAbortButtonState(True)
  1323.         Call ListFilesOnServer
  1324.         Call UpdateAbortButtonState(False)
  1325.         Call UpdateRemoteFilesState
  1326.         stbProgress.Panels(1).Text = ""
  1327.       Else                                 ' Assume the link is a file and download it.
  1328.         Call ReceiveFiles
  1329.       End If
  1330.       
  1331.     End Select
  1332.   End If
  1333.   cboRemotePath.Tag = 0 ' Allow responding to the click event again
  1334. End Sub
  1335. ' ****************************************************************************
  1336. ' If the right mouse button is clicked in the the local file list ListView
  1337. ' control, we will pop up the local operations menu
  1338. ' ****************************************************************************
  1339. Private Sub lstLocalFileList_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  1340.   If Button = 2 Then
  1341.     PopupMenu miLocal
  1342.   End If
  1343. End Sub
  1344. ' ****************************************************************************
  1345. ' If the right mouse button is clicked in the the remote file list ListView
  1346. ' control, we will popup the remote operations menu.
  1347. ' ****************************************************************************
  1348. Private Sub lstRemoteFileList_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  1349.   If Button = 2 Then
  1350.     PopupMenu miRemote
  1351.   End If
  1352. End Sub
  1353. ' ****************************************************************************
  1354. ' Drag and drop: Reactivate "dropping" in the local file list ListView control
  1355. ' once the drag operation has completed.
  1356. ' ****************************************************************************
  1357. Private Sub lstLocalFileList_OLECompleteDrag(Effect As Long)
  1358.   lstLocalFileList.OLEDropMode = ccOLEDropManual
  1359. End Sub
  1360. ' ****************************************************************************
  1361. ' Drag and drop: Call the ReceiveFiles method once the files are dropped in
  1362. ' the local file list ListView control.
  1363. ' ****************************************************************************
  1364. Private Sub lstLocalFileList_OLEDragDrop(Data As ComctlLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  1365.   If Data.GetFormat(vbCFText) Then
  1366.     Call ReceiveFiles
  1367.   End If
  1368. End Sub
  1369. ' ****************************************************************************
  1370. ' Drag and drop: Make sure that we are dragging text
  1371. ' ****************************************************************************
  1372. Private Sub lstLocalFileList_OLEDragOver(Data As ComctlLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single, State As Integer)
  1373.   If Not Data.GetFormat(vbCFText) Then
  1374.     Effect = vbDropEffectNone
  1375.   End If
  1376. End Sub
  1377. ' ****************************************************************************
  1378. ' Drag and drop: Make sure that we can't "drop" on the local file list
  1379. ' ListView control when dragging from it.
  1380. ' ****************************************************************************
  1381. Private Sub lstLocalFileList_OLEStartDrag(Data As ComctlLib.DataObject, AllowedEffects As Long)
  1382.   lstLocalFileList.OLEDropMode = ccOLEDropNone
  1383. End Sub
  1384. ' ****************************************************************************
  1385. ' Drag and drop: Reactivate "dropping" in the local file list ListView control
  1386. ' nce the drag operation has completed.
  1387. ' ****************************************************************************
  1388. Private Sub lstRemoteFileList_OLECompleteDrag(Effect As Long)
  1389.   lstRemoteFileList.OLEDropMode = ccOLEDropManual
  1390. End Sub
  1391. ' ****************************************************************************
  1392. ' Drag and drop: Call the SendFiles method once the files are dropped in the
  1393. ' local file list ListView control.
  1394. ' ****************************************************************************
  1395. Private Sub lstRemoteFileList_OLEDragDrop(Data As ComctlLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)
  1396.   If Data.GetFormat(vbCFText) Then
  1397.     Call SendFiles
  1398.   End If
  1399. End Sub
  1400. ' ****************************************************************************
  1401. ' Drag and drop: Make sure we are dragging text
  1402. ' ****************************************************************************
  1403. Private Sub lstRemoteFileList_OLEDragOver(Data As ComctlLib.DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single, State As Integer)
  1404.   If Not Data.GetFormat(vbCFText) Then
  1405.     Effect = vbDropEffectNone
  1406.   End If
  1407. End Sub
  1408. ' ****************************************************************************
  1409. ' Drag and drop: Make sure we can't "drop" on the remote file list ListView
  1410. ' control when dragging from it.
  1411. ' ****************************************************************************
  1412. Private Sub lstRemoteFileList_OLEStartDrag(Data As ComctlLib.DataObject, AllowedEffects As Long)
  1413.   lstRemoteFileList.OLEDropMode = ccOLEDropNone
  1414. End Sub
  1415. ' ****************************************************************************
  1416. ' If an account is required, the AccountRequired event will be triggered by
  1417. ' the XceedFtp object. This way, we have the opportunity to prompt the the
  1418. ' user to enter account information and then give this info to the XceedFtp
  1419. ' object in order for it to tell the FTP server about it.
  1420. ' ****************************************************************************
  1421. Private Sub xFtp_AccountRequired(sAccountName As String)
  1422.   Dim sNewAccountName As String
  1423.   sNewAccountName = InputBox("An account is required for this server.", MsgBoxTitle & "[Query]")
  1424.   sAccountName = sNewAccountName
  1425. End Sub
  1426. ' ****************************************************************************
  1427. ' The XceedFtp object triggers the Disconnected event whenever the library
  1428. ' disconnects or gets disconnected from the FTP server. We trap this event
  1429. ' in order to update our form's interface to reflect this occurence.
  1430. ' ****************************************************************************
  1431. Private Sub xFtp_Disconnected()
  1432.   MsgBox "Disconnected from FTP server " & xFtp.ServerAddress, vbOKOnly, MsgBoxTitle & "[Notice]"
  1433.   cboRemotePath.Clear
  1434.   stbProgress.Panels(1).Text = ""
  1435.   stbProgress.Panels(3).Text = ""
  1436.   Call ClearRemoteFileList
  1437.   Call ClearBars
  1438.   Call UpdateConnectionState(False)
  1439.   Call UpdateRemoteFilesState
  1440. End Sub
  1441. ' ****************************************************************************
  1442. ' The FileTransferStatus event provides us with a variety of information
  1443. ' regarding the transfer status of each individual file and the information
  1444. ' on the global progress of the current operation.
  1445. ' ****************************************************************************
  1446. Private Sub xFtp_FileTransferStatus(ByVal sLocalFilename As String, ByVal sRemoteFilename As String, ByVal lFileSize As Long, ByVal lBytesTransferred As Long, ByVal nBytesPercent As Integer, ByVal lTotalSize As Long, ByVal lTotalBytesTransferred As Long, ByVal nTotalBytesPercent As Integer, ByVal lTotalFiles As Long, ByVal lTotalFilesTransferred As Long, ByVal nTotalFilesPercent As Integer, ByVal lBytesPerSecond As Long, ByVal lTotalBytesPerSecond As Long)
  1447.   Call UpdateStatus(lBytesTransferred, lTotalBytesTransferred, nBytesPercent)
  1448. End Sub
  1449. ' ****************************************************************************
  1450. ' The ListingFolderItem event is triggered for each item being listed as a
  1451. ' result of a call to the XceedFtp object's ListFolderContents method. This
  1452. ' event provides us with information on every file, folder or link. Our
  1453. ' handler for the event (this procedure) adds the info to the remote folder
  1454. ' list ListView object.
  1455. ' ****************************************************************************
  1456. Private Sub xFtp_ListingFolderItem(ByVal sName As String, ByVal dtDate As Date, ByVal lFileSize As Long, ByVal eItemType As XceedFtpLibCtl.EXFFolderItemType, ByVal sUserData As String)
  1457.   Dim xItem As ListItem
  1458.   Select Case eItemType
  1459.   Case fitFolder  ' Item being listed is a folder
  1460.     Set xItem = lstRemoteFileList.ListItems.Add(, , sName, , 2)
  1461.     xItem.SubItems(1) = lFileSize
  1462.     xItem.SubItems(2) = dtDate
  1463.     xItem.SubItems(3) = "D" ' This column is used only for sorting by item type
  1464.   Case fitFile  ' Item being listed is a file
  1465.     Set xItem = lstRemoteFileList.ListItems.Add(, , sName, , 1)
  1466.     xItem.SubItems(1) = lFileSize
  1467.     xItem.SubItems(2) = dtDate
  1468.     xItem.SubItems(3) = "F" ' This column is used only for sorting by item type
  1469.   Case fitLink  ' Item being listed is a link
  1470.     Set xItem = lstRemoteFileList.ListItems.Add(, , sName, , 3)
  1471.     xItem.SubItems(1) = lFileSize
  1472.     xItem.SubItems(2) = dtDate
  1473.     xItem.SubItems(3) = "E" ' To sort in between D and F above!
  1474.   End Select
  1475. End Sub
  1476. ' ****************************************************************************
  1477. ' The LoggingCommandLine event is triggered by the XceedFtp object for every
  1478. ' command sent and received to/from the FTP server. Instead of writing our own
  1479. ' custom messages for every possible action in order to display progress on
  1480. ' our status bar, we will be using the information provided by XceedFtp.
  1481. ' ****************************************************************************
  1482. Private Sub xFtp_LoggingCommandLine(ByVal sLine As String, ByVal eCommandType As XceedFtpLibCtl.EXFCommandType)
  1483.   Call DisplayMessage(sLine)
  1484. End Sub
  1485. ' ****************************************************************************
  1486. ' If a password is required or if an invalid password was provided, the
  1487. ' PasswordRequired event will be triggered by the XceedFtp object. We then
  1488. ' have the chance to query the user for a password and provide it back to
  1489. ' the XceedFtp object to try again!
  1490. ' ****************************************************************************
  1491. Private Sub xFtp_PasswordRequired(sPassword As String)
  1492.   Dim sNewPassword As String
  1493.   sNewPassword = InputBox("Please enter the correct password", MsgBoxTitle & "[Query]")
  1494.   sPassword = sNewPassword  'Set the new password
  1495. End Sub
  1496. ' ****************************************************************************
  1497. ' The ReceivingFile event is triggered for every file that is about to be
  1498. ' received and provides our FTP Client with information regarding that
  1499. ' file. It also gives us the option to change the path and filename of
  1500. ' the file we are receiving.
  1501. ' ****************************************************************************
  1502. Private Sub xFtp_ReceivingFile(ByVal sRemoteFilename As String, sLocalFilename As String, ByVal lFileSize As Long)
  1503.   Call UpdateAction("Receiving " & sRemoteFilename)
  1504. End Sub
  1505. ' ****************************************************************************
  1506. ' If the file being received or sent exists, the ReplacingFile event gives
  1507. ' our sample application the option of overwriting, skipping it, etc...
  1508. ' ****************************************************************************
  1509. Private Sub xFtp_ReplacingFile(sFilename As String, ByVal dtDate As Date, ByVal lFileSize As Long, ByVal sRemoteFilename As String, eAction As XceedFtpLibCtl.EXFReplaceAction)
  1510.   Dim nMsgResult As VbMsgBoxResult
  1511.   ' Ask user if they want to replace the existing file.
  1512.   nMsgResult = MsgBox(sFilename & " already exits. Do you want to replace it?", vbYesNo + vbQuestion, MsgBoxTitle & "[Confirm]")
  1513.   If nMsgResult = vbYes Then
  1514.     eAction = fraOverwrite  'Replace the file
  1515.   Else
  1516.     eAction = fraSkip 'Skip the file
  1517.   End If
  1518. End Sub
  1519. ' ****************************************************************************
  1520. ' The SendFile event is triggered for every file that is about to be sent and
  1521. ' provides us with information regaring that file, It also gives us the option
  1522. ' to change the filename of the file we are sending.
  1523. ' ****************************************************************************
  1524. Private Sub xFtp_SendingFile(ByVal sLocalFilename As String, sRemoteFilename As String, ByVal lFileSize As Long)
  1525.   Call UpdateAction("Sending " & sLocalFilename)
  1526. End Sub
  1527. ' ****************************************************************************
  1528. ' For every file that is skipped, wether sending or receiveing, the
  1529. ' XceedFtp object will trigger the SkippingFile event. We then know which
  1530. ' file is being skipped and for what reason. We can then display a message
  1531. ' to the user.
  1532. ' ****************************************************************************
  1533. Private Sub xFtp_SkippingFile(ByVal sLocalFilename As String, ByVal sRemoteFilename As String, ByVal eSkippingReason As XceedFtpLibCtl.EXFError)
  1534.   Dim ReasonString As String
  1535.   If sLocalFilename = "" Then
  1536.     Call DisplayMessage(CStr(sRemoteFilename & " was skipped. Reason:" & xFtp.GetResultDescription(eSkippingReason)))
  1537.   End If
  1538.   If sRemoteFilename = "" Then
  1539.     Call DisplayMessage(CStr(sLocalFilename & " was skipped. Reason:" & xFtp.GetResultDescription(eSkippingReason)))
  1540.   End If
  1541. End Sub
  1542. ' ****************************************************************************
  1543. ' Add a new path to the remote combo box
  1544. ' ****************************************************************************
  1545. Public Sub AddToRemotePaths(ByVal sPathToAdd As String)
  1546.   ' Check if the path already exists
  1547.   If Not ComboPathExists(sPathToAdd, cboRemotePath) Then ' If it does not exist, then add it
  1548.     Call cboRemotePath.AddItem(sPathToAdd)
  1549.     cboRemotePath.ListIndex = cboRemotePath.NewIndex
  1550.   Else
  1551.     cboRemotePath.Text = sPathToAdd
  1552.   End If
  1553. End Sub
  1554. ' ****************************************************************************
  1555. ' Update the status bar panels while sending and receiving
  1556. ' ****************************************************************************
  1557. Public Sub UpdateStatus(ByVal lBytes As Long, ByVal lTotalBytes As Long, ByVal nBytesPercent As Integer)
  1558.   stbProgress.Panels(2).Text = CStr(lBytes)
  1559.   stbProgress.Panels(3).Text = "Total : " & CStr(lTotalBytes)
  1560.   prgStatus.Value = nBytesPercent
  1561. End Sub
  1562. ' ****************************************************************************
  1563. ' Update the first panel of the status bar to display the name of the file
  1564. ' being sent or received as well as notify the user when the operation is
  1565. ' complete
  1566. ' ****************************************************************************
  1567. Public Sub UpdateAction(ByVal sMessage As String)
  1568.   stbProgress.Panels(1).Text = sMessage
  1569. End Sub
  1570. ' ****************************************************************************
  1571. ' Add a new path to the local path selection combo box
  1572. ' ****************************************************************************
  1573. Private Sub m_xLocalPaths_AddToLocalPaths(ByVal sPathToAdd As String)
  1574.   ' Check first to see if the path exists
  1575.   If Not ComboPathExists(sPathToAdd, cboLocalPath) Then
  1576.     Call cboLocalPath.AddItem(UCase(sPathToAdd))  ' If it does not exist, we add it
  1577.     cboLocalPath.ListIndex = cboLocalPath.NewIndex
  1578.   Else
  1579.     cboLocalPath.Text = sPathToAdd
  1580.   End If
  1581. End Sub
  1582. ' ****************************************************************************
  1583. ' Display a message on the form
  1584. ' ****************************************************************************
  1585. Public Sub DisplayMessage(ByVal sMessage As String)
  1586.   lstConnectionInfo.AddItem (sMessage)
  1587.   lstConnectionInfo.ListIndex = lstConnectionInfo.ListCount - 1
  1588. End Sub
  1589. ' ****************************************************************************
  1590. ' Add a new entry to the local file list ListView control. We will also set
  1591. ' the appropriate icon depending on if the item is a file a folder.
  1592. ' ****************************************************************************
  1593. Private Sub m_xLocalPaths_UpdateLocalEntry(ByVal sName As String, ByVal dtDate As Date, ByVal lSize As Long, ByVal nAttrib As Integer)
  1594.   Dim xItem As ListItem
  1595.        
  1596.   If nAttrib = -1 Then                                                ' Unknown item type
  1597.     Set xItem = lstLocalFileList.ListItems.Add(, , sName, , 1)        ' If there was a problem
  1598.     xItem.SubItems(1) = lSize
  1599.     xItem.SubItems(2) = dtDate
  1600.     xItem.SubItems(3) = "F"                                           ' For sorting by item type
  1601.   ElseIf nAttrib And vbDirectory Then
  1602.     Set xItem = lstLocalFileList.ListItems.Add(, , UCase(sName), , 2) ' If it was a folder
  1603.     xItem.SubItems(1) = ""
  1604.     xItem.SubItems(2) = dtDate
  1605.     xItem.SubItems(3) = "D"                                           ' For sorting by item type
  1606.   Else  'Is a file
  1607.     Set xItem = lstLocalFileList.ListItems.Add(, , sName, , 1)        ' If it was a file
  1608.     xItem.SubItems(1) = lSize
  1609.     xItem.SubItems(2) = dtDate
  1610.     xItem.SubItems(3) = "F"                                           ' For sorting by item type
  1611.   End If
  1612. End Sub
  1613. ' ****************************************************************************
  1614. ' Add the logical system drive to the local path selection combo box
  1615. ' ****************************************************************************
  1616. Private Sub m_xLocalPaths_LogicalDriveFound(ByVal sDriveToAdd As String)
  1617.   cboLocalPath.AddItem (UCase(sDriveToAdd))
  1618. End Sub
  1619.